import requests
import json, cv2
from base64 import b64decode
import numpy as np
import logging

def result_post():
    url = "http://8.134.53.114:8277/visual/uavAiAlarm/msgUpload"
    json_data = {}
    """南水直播检测报警测试"""
    logging.info("|INFO: post data to {}|".format(url))
    ret = requests.post(url=url,json=json_data)
    status_code = ret.status_code
    if status_code != 200:
        logging.error("|ERR: code {}, result_post fail|".format(status_code))


def post_test():
    json_data = {
        "id":0,
        "tag":"",
        "data":{

        }
    }
    from base64 import b64decode, b64encode
    file_path = "data/input/eve/屏幕采集_20240607_145352.081.jpg"
    img_np = cv2.imread(file_path)
    ret, img_jpg_encode = cv2.imencode(".jpg",img_np)
    img_byte = img_jpg_encode.tobytes()
    img_b64 = b64encode(img_byte).decode('utf-8')

    json_data = {
        "id": 1,
        "tag": "task",
        "data": {
            "tag":"obj_detect",
            "data":{
                "tag":"DET",
                "data":{
                    "id": 1,
                    "Base64Decode_mode": "RGB",
                    "input_data":img_b64
                }
            }
        }
    }
    url = "http://0.0.0.0:2682/detect"

    request = requests.post(url=url,json = json_data)
    with open("data/output/temp_file.json","w") as f:
        jsondata = json.loads(request.text)
        json.dump(jsondata,f)

    print(request)



if __name__ == "__main__":
    # post_test()
    # post_test_building_change()
    # result_post()
    post_test()
    # stop_rtmp()


